package Messages;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.mysql.jdbc.ResultSet;

import Server.SQLConnection;

import ocsf.server.ConnectionToClient;
/**
 * This class implements the Edit Reservation to db
 *   @author Shlomit Yosfan
 * @author Nofar Sutliman
 */
public class MessageEditReservation {
	
	private ConnectionToClient client ;
	private String[] str; 
/**
 * constructor of this class 
 * @param str
 * @param client
 */
	public MessageEditReservation(String[] str, ConnectionToClient client) {
		this.client= client ;
		this.str= str; 	
	}
	/**
	 * editing  Reservation to the DB	
	 * @throws SQLException
	 * @throws IOException
	 */
	public void EditReservation() throws SQLException, IOException{
		SQLConnection sc = new SQLConnection();

		java.sql.PreparedStatement ps=sc.getConnection().prepareStatement("SELECT * FROM db.reservation where ReservaionID = ?;");
		ps.setString(1,str[1]);

		ResultSet rs= (ResultSet) ps.executeQuery();
		
		ArrayList<Object> editreservation =new ArrayList<Object>();
		editreservation.add("EditReservation");
		while (rs.next())
		{
			editreservation.add(rs.getInt(1));
			editreservation.add(rs.getString(2));
			editreservation.add(rs.getString(3));
			editreservation.add(rs.getString(4));
			editreservation.add(rs.getString(5));
			editreservation.add(rs.getString(6));
			editreservation.add(rs.getString(7));
			editreservation.add(rs.getString(8));

		}
		client.sendToClient(editreservation);
		
		ps.close();
		rs.close();
		
		
		
	}
}

